{
 "cells": [
  {
   "cell_type": "code",
   "id": "8eddafd0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:08:37.525546Z",
     "start_time": "2025-07-31T01:08:37.005297Z"
    }
   },
   "source": [
    "gimport pandas as pd\n",
    "df = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9],[10,11,12]],columns=[\"A\",\"B\",\"C\"],index=[1,2,3,4])"
   ],
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Loading In dataframes from files",
   "id": "1f7317a91537acbe"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:23:36.896941Z",
     "start_time": "2025-07-31T01:23:14.676917Z"
    }
   },
   "cell_type": "code",
   "source": [
    "coffee = pd.read_csv('../warmup-data/coffee.csv')\n",
    "results = pd.read_parquet('../data/results.parquet', engine='pyarrow')\n",
    "bios = pd.read_csv('../data/bios.csv')\n",
    "olympics_data = pd.read_excel('./data/olympics-data.xlsx',sheet_name='results')"
   ],
   "id": "a5e0c42c19826a1a",
   "outputs": [],
   "execution_count": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:13:31.002158Z",
     "start_time": "2025-07-31T01:13:30.982432Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 展示表结构及数据\n",
    "display(coffee)\n",
    "# 获取开头的几行数据\n",
    "coffee.head()\n",
    "# 获取末尾的几行数据\n",
    "coffee.tail(10)\n",
    "# 获取随机的几行数据\n",
    "coffee.sample(5)"
   ],
   "id": "4ea55a2418572090",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "         Day Coffee Type  Units Sold\n",
       "0     Monday    Espresso          25\n",
       "1     Monday       Latte          15\n",
       "2    Tuesday    Espresso          30\n",
       "3    Tuesday       Latte          20\n",
       "4  Wednesday    Espresso          35"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Coffee Type</th>\n",
       "      <th>Units Sold</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Monday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Monday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Wednesday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:20:24.580702Z",
     "start_time": "2025-07-31T01:20:24.561436Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# loc根据行索引及列标题获取数据\n",
    "coffee.loc[1:2,\"Day\"]\n",
    "# iloc根据索引代码获取数据\n",
    "coffee.iloc[0:4,[0,2]]"
   ],
   "id": "25d2c258f8da807f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "       Day  Units Sold\n",
       "0   Monday          25\n",
       "1   Monday          15\n",
       "2  Tuesday          30\n",
       "3  Tuesday          20"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Units Sold</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Monday</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Monday</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# 给表结构设定索引\n",
    "coffee.index = coffee['Day']\n",
    "# 获取单一数值(使用行索引及列标题或行列序号)\n",
    "coffee.at[0,\"Units Sold\"]\n",
    "coffee.iat[0,2]"
   ],
   "id": "eb502f31ddb44917"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:34:13.513163Z",
     "start_time": "2025-07-31T01:34:13.493865Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 排序函数，ascending为升降序1为升序，0为降序\n",
    "coffee.sort_values(by=[\"Units Sold\"],ascending=True)\n",
    "coffee.sort_values([\"Units Sold\",\"Coffee Type\"],ascending=[0,1])"
   ],
   "id": "56e9cfc05caf99ee",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Day Coffee Type  Units Sold\n",
       "8      Friday    Espresso          45\n",
       "10   Saturday    Espresso          45\n",
       "12     Sunday    Espresso          45\n",
       "6    Thursday    Espresso          40\n",
       "4   Wednesday    Espresso          35\n",
       "9      Friday       Latte          35\n",
       "11   Saturday       Latte          35\n",
       "13     Sunday       Latte          35\n",
       "2     Tuesday    Espresso          30\n",
       "7    Thursday       Latte          30\n",
       "0      Monday    Espresso          25\n",
       "5   Wednesday       Latte          25\n",
       "3     Tuesday       Latte          20\n",
       "1      Monday       Latte          15"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Day</th>\n",
       "      <th>Coffee Type</th>\n",
       "      <th>Units Sold</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Friday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Saturday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Sunday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Thursday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Wednesday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Friday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Saturday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Sunday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Thursday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Monday</td>\n",
       "      <td>Espresso</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Wednesday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tuesday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Monday</td>\n",
       "      <td>Latte</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:37:16.016972Z",
     "start_time": "2025-07-31T01:37:15.985909Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 使用循环遍历数组\n",
    "for index,row in coffee.iterrows():\n",
    "    print(index)\n",
    "    print(row)\n",
    "    print(\"Coffee Type Of Row\",row[\"Coffee Type\"])"
   ],
   "id": "d7bb9045de4bac1f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "Day              Monday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           25\n",
      "Name: 0, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "1\n",
      "Day            Monday\n",
      "Coffee Type     Latte\n",
      "Units Sold         15\n",
      "Name: 1, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "2\n",
      "Day             Tuesday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           30\n",
      "Name: 2, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "3\n",
      "Day            Tuesday\n",
      "Coffee Type      Latte\n",
      "Units Sold          20\n",
      "Name: 3, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "4\n",
      "Day            Wednesday\n",
      "Coffee Type     Espresso\n",
      "Units Sold            35\n",
      "Name: 4, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "5\n",
      "Day            Wednesday\n",
      "Coffee Type        Latte\n",
      "Units Sold            25\n",
      "Name: 5, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "6\n",
      "Day            Thursday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           40\n",
      "Name: 6, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "7\n",
      "Day            Thursday\n",
      "Coffee Type       Latte\n",
      "Units Sold           30\n",
      "Name: 7, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "8\n",
      "Day              Friday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           45\n",
      "Name: 8, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "9\n",
      "Day            Friday\n",
      "Coffee Type     Latte\n",
      "Units Sold         35\n",
      "Name: 9, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "10\n",
      "Day            Saturday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           45\n",
      "Name: 10, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "11\n",
      "Day            Saturday\n",
      "Coffee Type       Latte\n",
      "Units Sold           35\n",
      "Name: 11, dtype: object\n",
      "Coffee Type Of Row Latte\n",
      "12\n",
      "Day              Sunday\n",
      "Coffee Type    Espresso\n",
      "Units Sold           45\n",
      "Name: 12, dtype: object\n",
      "Coffee Type Of Row Espresso\n",
      "13\n",
      "Day            Sunday\n",
      "Coffee Type     Latte\n",
      "Units Sold         35\n",
      "Name: 13, dtype: object\n",
      "Coffee Type Of Row Latte\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:39:59.715608Z",
     "start_time": "2025-07-31T01:39:59.662252Z"
    }
   },
   "cell_type": "code",
   "source": "bios.head()",
   "id": "214479fe5300624c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   athlete_id                   name   born_date    born_city  \\\n",
       "0           1  Jean-François Blanchy  1886-12-12     Bordeaux   \n",
       "1           2         Arnaud Boetsch  1969-04-01       Meulan   \n",
       "2           3           Jean Borotra  1898-08-13     Biarritz   \n",
       "3           4        Jacques Brugnon  1895-05-11  Paris VIIIe   \n",
       "4           5           Albert Canet  1878-04-17   Wandsworth   \n",
       "\n",
       "            born_region born_country     NOC  height_cm  weight_kg   died_date  \n",
       "0               Gironde          FRA  France        NaN        NaN  1960-10-02  \n",
       "1              Yvelines          FRA  France      183.0       76.0         NaN  \n",
       "2  Pyrénées-Atlantiques          FRA  France      183.0       76.0  1994-07-17  \n",
       "3                 Paris          FRA  France      168.0       64.0  1978-03-20  \n",
       "4               England          GBR  France        NaN        NaN  1930-07-25  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>athlete_id</th>\n",
       "      <th>name</th>\n",
       "      <th>born_date</th>\n",
       "      <th>born_city</th>\n",
       "      <th>born_region</th>\n",
       "      <th>born_country</th>\n",
       "      <th>NOC</th>\n",
       "      <th>height_cm</th>\n",
       "      <th>weight_kg</th>\n",
       "      <th>died_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Jean-François Blanchy</td>\n",
       "      <td>1886-12-12</td>\n",
       "      <td>Bordeaux</td>\n",
       "      <td>Gironde</td>\n",
       "      <td>FRA</td>\n",
       "      <td>France</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1960-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Arnaud Boetsch</td>\n",
       "      <td>1969-04-01</td>\n",
       "      <td>Meulan</td>\n",
       "      <td>Yvelines</td>\n",
       "      <td>FRA</td>\n",
       "      <td>France</td>\n",
       "      <td>183.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Jean Borotra</td>\n",
       "      <td>1898-08-13</td>\n",
       "      <td>Biarritz</td>\n",
       "      <td>Pyrénées-Atlantiques</td>\n",
       "      <td>FRA</td>\n",
       "      <td>France</td>\n",
       "      <td>183.0</td>\n",
       "      <td>76.0</td>\n",
       "      <td>1994-07-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Jacques Brugnon</td>\n",
       "      <td>1895-05-11</td>\n",
       "      <td>Paris VIIIe</td>\n",
       "      <td>Paris</td>\n",
       "      <td>FRA</td>\n",
       "      <td>France</td>\n",
       "      <td>168.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>1978-03-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Albert Canet</td>\n",
       "      <td>1878-04-17</td>\n",
       "      <td>Wandsworth</td>\n",
       "      <td>England</td>\n",
       "      <td>GBR</td>\n",
       "      <td>France</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1930-07-25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 28
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:41:27.571299Z",
     "start_time": "2025-07-31T01:41:27.547519Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 筛选函数\n",
    "bios.loc[bios[\"height_cm\"] > 225,[\"name\",\"height_cm\"]]\n"
   ],
   "id": "f7148d7d469ca20a",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           name  height_cm\n",
       "89070  Yao Ming      226.0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>height_cm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>89070</th>\n",
       "      <td>Yao Ming</td>\n",
       "      <td>226.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 31
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:43:00.662995Z",
     "start_time": "2025-07-31T01:43:00.658336Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 不实用loc函数执行筛选函数\n",
    "bios[bios['height_cm'] > 225][[\"name\",\"height_cm\"]]"
   ],
   "id": "4c3734dc34a27df2",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           name  height_cm\n",
       "89070  Yao Ming      226.0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>height_cm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>89070</th>\n",
       "      <td>Yao Ming</td>\n",
       "      <td>226.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 35
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:45:20.628777Z",
     "start_time": "2025-07-31T01:45:20.615188Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 不使用loc函数执行多重筛选函数\n",
    "bios[(bios['height_cm'] > 218) & (bios['born_country']=='USA')][[\"name\",\"height_cm\"]]"
   ],
   "id": "145e6c5c85f887ea",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "                name  height_cm\n",
       "5781  Tommy Burleson      223.0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>height_cm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5781</th>\n",
       "      <td>Tommy Burleson</td>\n",
       "      <td>223.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T03:30:48.240015Z",
     "start_time": "2025-07-31T03:30:48.146242Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 通过字符串进行筛选\n",
    "bios[bios[\"name\"].str.contains(\"Yao|Fen\",case=False,regex=False)][[\"name\",\"height_cm\"]]"
   ],
   "id": "e0b03f9425f4655e",
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'bios' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mNameError\u001B[39m                                 Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[1]\u001B[39m\u001B[32m, line 2\u001B[39m\n\u001B[32m      1\u001B[39m \u001B[38;5;66;03m# 通过字符串进行筛选\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m2\u001B[39m \u001B[43mbios\u001B[49m[bios[\u001B[33m\"\u001B[39m\u001B[33mname\u001B[39m\u001B[33m\"\u001B[39m].str.contains(\u001B[33m\"\u001B[39m\u001B[33mYao|Fen\u001B[39m\u001B[33m\"\u001B[39m,case=\u001B[38;5;28;01mFalse\u001B[39;00m,regex=\u001B[38;5;28;01mFalse\u001B[39;00m)][[\u001B[33m\"\u001B[39m\u001B[33mname\u001B[39m\u001B[33m\"\u001B[39m,\u001B[33m\"\u001B[39m\u001B[33mheight_cm\u001B[39m\u001B[33m\"\u001B[39m]]\n",
      "\u001B[31mNameError\u001B[39m: name 'bios' is not defined"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-31T01:52:44.794185Z",
     "start_time": "2025-07-31T01:52:44.771046Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 序列函数\n",
    "seqresults = bios.query(\"height_cm>225\")\n",
    "seqresults.loc[:,[\"name\",\"height_cm\"]]"
   ],
   "id": "95dde5b035d20c88",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           name  height_cm\n",
       "89070  Yao Ming      226.0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>height_cm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>89070</th>\n",
       "      <td>Yao Ming</td>\n",
       "      <td>226.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 47
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
